/*  TOOLBAR MENU FUNCTIONS */
var currentopened = null;
function menu_initialization(){register_menu_handlers();}

function register_menu_handlers(){
	try{
		var all;
		if(document.all){
			all=document.all;
		}else{
			all=document.getElementsByTagName("*");
		}
		for(var i=0;i<all.length;i++){
			if(all[i].id){
				if(all[i].id.indexOf("itm_")==0){
					if(submenu=menu_get_sub(all[i])){
						addEvent(all[i],"mouseover",menu_mousein);
						addEvent(all[i],"mouseout",menuowner_mouseout);
						submenu.menu_owner=all[i];
					}
				}
				if(all[i].id.indexOf("sub_")==0){
					addEvent(all[i],"mouseout",menu_mouseout);
					addEvent(all[i],"click",menu_close_force);
				}
			}
		}
	}catch(e){
		logging("Error register_menu_handlers:"+e.message);
	}
}

function menu_find_parent_id(object){
	try{
		if(!object.id){
			if(object.parentNode){
				return menu_find_parent_id(object.parentNode);
			}else{
				return false;
			}
		}else{
			return object.id;
		}
	}catch(e){
		logging("Error menu_find_parent_id:"+e.message);
	}
}

function menu_get_sub(object){
	try{
		var id=new String(menu_find_parent_id(object)).substring(4);
		var submenu_id="sub_"+id;
		return getElement(submenu_id);
	}catch(e){
		logging("Error menu_get_sub:"+e.message);
	}
}

function menu_in_menu(object){
	try{
		object=object.parentNode;
		while(object.parentNode){
			var id=object.id.substring(4);
			if(id&&(getElement("itm_"+id)||getElement("sub_"+id))){
				return id;
			}
			object=object.parentNode;
		}
		return false;
	}catch(e){
		logging("Error menu_in_menu:"+e.message);
	}
}

function menu_mousein(event){
	try{
		event		=event || window.event;
		var object	=event.target || event.srcElement;
		if(menu_in_menu(object)){
			var submenu=menu_get_sub(object);
			if(submenu){
				clearTimeout(submenu.timer);submenu.timer=false;
				if(submenu.childNodes.length){
					submenu.style.display="block";
				}
				if(!submenu.menu_owner.oldClass){
					submenu.menu_owner.oldClass=submenu.menu_owner.className;
					submenu.menu_owner.className=submenu.menu_owner.className+"_active";
				}
			}
		}
		return false;
	}catch(e){
		logging("Error menu_mousein:"+e.message);
	}
}

function menu_mouseout(event){
	try{
		event		=event || window.event;
		var object	=event.target || event.srcElement;
		var submenu	=menu_get_sub(object);
		if(submenu){
			//logging('We close '+submenu.id);
			menu_close_wait(submenu.id);
		}
		return false;
	}catch(e){
		logging("Error menu_mouseout:"+e.message);
	}
}
function menu_close_sub(id){
	try{
		submenutoclose=getElement(id);
		if(submenutoclose){
			submenutoclose.style.display="none";
			if(submenutoclose.menu_owner.oldClass){
				submenutoclose.menu_owner.className=submenutoclose.menu_owner.oldClass;
				submenutoclose.menu_owner.oldClass=false;
			}
		}
	}catch(e){
		logging("Error menu_close_sub:"+e.message);
	}
}

function menu_close_wait(id){
	submenu=getElement(id);
	if(submenu){
		if(!submenu.timer){
			submenu.timer=setTimeout("menu_close_sub('"+id+"')",300);
		}
	}
}

function menu_close_force(event){
	try{
		event		=event || window.event;
		var object	=event.target || event.srcElement;
		var id		=menu_in_menu(object);
		var submenu	=getElement(id);
		submenutoclose	=submenu;
		menu_close_sub("sub_"+id);
	}catch(e){
		logging("Error menu_close_force:"+e.message);
	}
}

function menuowner_mouseout(event){
	try{
		event		=event || window.event;
		var object	=event.target || event.srcElement;
		menu_close_wait("sub_"+menu_in_menu(object));
	}catch(e){
		logging("Error menu_close_force:"+e.message);
	}
}
/*  TOOLBAR MENU FUNCTIONS */
